package chapter14.section4;

// 程序14-8a：一个登陆的Panel

import javax.swing.*;

public class LoginPanel extends JPanel {
    // 在构造方法之外声明两个输入组件成员，主要是为了在构造方法之外能够得到输入内容
    JTextField txtName;
    JPasswordField txtPwd;
    MainFrame mfrm;// 用来引用主窗口,作用见14.6.3节内容

    public LoginPanel(MainFrame mfrm) {
        super();
        this.mfrm = mfrm;
        Box box1 = Box.createHorizontalBox();
        JLabel lblName = new JLabel("登录账号:");
        txtName = new JTextField(20);
        box1.add(lblName);
        box1.add(Box.createHorizontalStrut(20));
        box1.add(txtName);

        Box box2 = Box.createHorizontalBox();
        JLabel lblPwd = new JLabel("登录密码:");
        txtPwd = new JPasswordField(20);
        box2.add(lblPwd);
        box2.add(Box.createHorizontalStrut(20));
        box2.add(txtPwd);

        Box box3 = Box.createHorizontalBox();
        JButton btnLogin = new JButton("登录");
        btnLogin.setActionCommand("login");// 指定按钮的动作命令
        box3.add(btnLogin);

        Box box = Box.createVerticalBox();
        box.add(box1);
        box.add(Box.createVerticalStrut(20));
        box.add(box2);
        box.add(Box.createVerticalStrut(20));
        box.add(box3);
        this.add(box);

    }
}